/*
 * @file     g_rtc.h
 * @brief    This file contains all the functions prototypes for the RTC firmware library.
 *
 * Change Logs:
 * Date           Author             Version        Notes
 * 2021-05-28     xubo               V1.0.0         the first version
 */

#ifndef __G_RTC_H__
#define __G_RTC_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "g_1903.h"
#include "g_system.h"
#include "g_vbat_ctr.h"
#include "g_timer.h"
#include "g_sysctrl.h"

/** @defgroup RTC_Clk_Types
 * @{
 */
#define IS_RTC_SEL(rtc)                         ((rtc == MRTCLSI) || (rtc == MRTCLSE))

#define RTCLSE_CLKSOURCE_LSI32K                 0
#define RTCLSE_CLKSOURCE_LSE32K                 1
#define IS_RTCLSE_CLKSOURCE_SEL(rtcsource)      ((rtcsource == RTCLSE_CLKSOURCE_LSI32K)||(rtcsource == RTCLSE_CLKSOURCE_LSE32K))

typedef struct
{
    uint8_t rtclse_irq;
    uint8_t rtclse_sec_irq;
    uint8_t rtclse_alarm_irq;
    uint8_t rtclsi_irq;
    uint8_t rtclsi_sec_irq;
    uint8_t rtclsi_alarm_irq;
} G_RTC_IRQ_TypeDef;

G_ErrorStatus G_RTC_Init(RTC_TypeDef *RTCx);
void G_RTC_ResetCounter(RTC_TypeDef *RTCx);
uint32_t G_RTC_GetCounter(RTC_TypeDef *RTCx);
void G_RTC_SetAlarm(RTC_TypeDef *RTCx, uint32_t AlarmValue);
void G_RTC_SetRefRegister(RTC_TypeDef *RTCx, uint32_t RefValue);
uint32_t G_RTC_GetRefRegister(RTC_TypeDef *RTCx);
void G_RTC_ITConfig(RTC_TypeDef *RTCx, uint32_t rtc_irqx, G_FunctionalState NewState);
void G_RTC_LseClkConfig(uint8_t RTCLSE_ClkSource,G_FunctionalState NewState);
void G_RTC_ClearITPendingBit(RTC_TypeDef *RTCx, uint32_t rtc_irqx);
G_RTC_IRQ_TypeDef G_RTC_GetITStatus(void);
void G_RTC_Calibration(void);
#ifdef __cplusplus
}
#endif

#endif

/************************ (C) COPYRIGHT GKT *****END OF FILE****/
